package cn.itsource.ymcc.mq;

//MQ的消费者

import cn.itsource.ymcc.domain.MediaFile;
import cn.itsource.ymcc.service.IMediaFileService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@RocketMQMessageListener(
        topic = "media-topic",
        consumerGroup = "group_media",
        selectorExpression = "*",
        messageModel =  MessageModel.CLUSTERING // 消费的模式
)
@Service
public class MediaComsumer implements RocketMQListener<MediaFile> {

    @Autowired
    private IMediaFileService mediaFileService;

    @Override
    public void onMessage(MediaFile mediaFile) {
        System.out.println("消费者收到消息："+mediaFile.getFileName());
        // 通过ffmpeg 推流到HLS 服务器
        mediaFileService.handleFile2m3u8(mediaFile);
        System.out.println("消费者推流完成！！！");
    }
}
